Array is the collection of keys and values. The key can either be an integer or a string. The value can be of any type.
This is usually done for single-line arrays, i.e. array(1, 2) is preferred over array(1, 2, ). For multi-line arrays on the other hand the trailing comma is commonly used, as it allows easier addition of new elements at the end.
Types of array
1.single
2. two dimensional
3. multi- dimensionnal
1. single dimensional array:
2 3 4 5 6 7 8 |
$array=array("men","women","child"); $array[0]="men"; $array[1]="women"; $array[2]="child"; |
2. two dimensional array:
2 3 4 5 6 7 8 9 10 |
$array1=array( array("men","women","child"); ); echo $array1[0][0]="men"; echo $array1[0][1]="women"; echo $array1[0][2]="child"; |
3. mutli-dimensional array:
2 3 4 5 6 7 8 9 10 11 12 13 14 |
$array1=array( array("men","women","child"), array("cow","elephant","dog"), array("apple","banana","mango") ); $array1[0][0]="men" $array1[0][1]="women" $array1[0][2]="Child" $array1[1][0]="cow" $array1[1][1]="elephant" $array1[1][2]="dog" $array1[2][0]="apple" $array1[2][1]="banana" $array1[2][2]="mango" |
you can also watch my video tutorials:
Pradeep Maurya is the Professional Web Developer & Designer and the Founder of “Tutorials website”. He lives in Delhi and loves to be a self-dependent person. As an owner, he is trying his best to improve this platform day by day. His passion, dedication and quick decision making ability to stand apart from others. He’s an avid blogger and writes on the publications like Dzone, e27.co